﻿#同一文件夹下多工作簿内多sheet合并，且末列写入工作簿名称
print("* * * * * *正在处理请稍后 * * * * * *\n")
# -*- coding: utf-8 -*-
import os,xlrd,xlsxwriter
#:xlrd==1.2.0
filePath = r'C:\Users\snowe\Desktop\stock'
f_name = os.listdir(filePath)
source_xlsx= []
for i in f_name:
	source_xlsx.append(filePath + '\\' + i)
target_xlsx = r"C:\Users\snowe\Desktop\报表.xlsx"
data = []
for i in source_xlsx:
	wb = xlrd.open_workbook(i)
	for sheet in wb.sheets():
		for rownum in range(sheet.nrows):
			a = sheet.row_values(rownum)
			a.append(i.replace((filePath + '\\'), ''))
			data.append(a)	
workbook = xlsxwriter.Workbook(target_xlsx)
worksheet = workbook.add_worksheet()
font = workbook.add_format({"font_size":10})
for i in range(len(data)):
	for j in range(len(data[i])):
		worksheet.write(i, j, data[i][j], font)
workbook.close()
print("+\n|\n+\n|\n+\n|\n")
print("* * * * * *合并完成* * * * * *")
print("---按Enter键结束---")
input()